package com.atguigu.upp.service;

import com.atguigu.upp.bean.TagInfo;
import com.atguigu.upp.bean.TaskInfo;
import com.atguigu.upp.bean.TaskTagRule;
import com.atguigu.upp.mapper.TagInfoMapper;
import com.atguigu.upp.mapper.TaskInfoMapper;
import com.atguigu.upp.mapper.TaskTagRuleMapper;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * Created by Smexy on 2022/11/11
 *
 *      把常用的查询Mysql的方法集成
 */
public class MysqlDBService
{

    private TagInfoMapper tagInfoMapper;
    private TaskInfoMapper taskInfoMapper;
    private TaskTagRuleMapper taskTagRuleMapper;

    public MysqlDBService(SqlSession sqlSession){
        tagInfoMapper = sqlSession.getMapper(TagInfoMapper.class);
        taskInfoMapper = sqlSession.getMapper(TaskInfoMapper.class);
        taskTagRuleMapper = sqlSession.getMapper(TaskTagRuleMapper.class);
    }

    public TagInfo getTagInfoByTaskId(String taskId){
        if (StringUtils.isBlank(taskId)){
            throw new RuntimeException("taskId非法!");
        }
        return tagInfoMapper.getTagInfoByTaskId(taskId);
    }

    public TaskInfo getTaskInfoByTaskId(String taskId){
        if (StringUtils.isBlank(taskId)){
            throw new RuntimeException("taskId非法!");
        }
        return taskInfoMapper.getTaskInfoByTaskId(taskId);
    }

    public List<TaskTagRule> getTaskTagRulesByTaskId(String taskId){
        if (StringUtils.isBlank(taskId)){
            throw new RuntimeException("taskId非法!");
        }
        return taskTagRuleMapper.getTaskTagRulesByTaskId(taskId);
    }

    public List<TagInfo> getTagInfoTodayExecute(){

        return tagInfoMapper.getTagInfoTodayExecute();
    }
}
